#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <string>
#include <cstring>
#include <cctype>
#include <assert.h>
using namespace std;
#define inf (1<<30)
#define N 1200
struct Edge {
 int to, next, value, cost;
} e[40 * N + 10];
int cnt, p[N], pre[N], vis[N], dis[N], pos[N];
int q[N * 400], flow, nv, src, des;
void add(int u, int v, int value, int cost) {
 e[cnt].to = v;
 e[cnt].value = value;
 e[cnt].cost = cost;
 e[cnt].next = p[u];
 p[u] = cnt++;
 e[cnt].to = u;
 e[cnt].value = 0;
 e[cnt].cost = -cost;
 e[cnt].next = p[v];
 p[v] = cnt++;
}
bool spfa(int s, int t, int n) {
 for (int i = 0; i <= n; i++) {
    dis[i] = inf;
    vis[i] = 0;
    pre[i] = -1;
 }
 dis[s] = 0;
 vis[s] = 1;
 int head = 0, tail = 0, cur;
 q[tail++] = s;
 while (head < tail) {
    cur = q[head++], vis[cur] = 0;
    for (int i = p[cur]; i != -1; i = e[i].next) {
     if (e[i].value > 0 && dis[e[i].to] > dis[cur] + e[i].cost) {
      dis[e[i].to] = dis[cur] + e[i].cost;
      pre[e[i].to] = cur;
      pos[e[i].to] = i;
      if (!vis[e[i].to]) {
       vis[e[i].to] = 1;
       q[tail++] = e[i].to;
      }
     }
    }
 }
 return dis[t] == inf;
}
int min_cost_flow(int s, int t, int n) {
 flow = 0;
 int cost = 0;
 while (!spfa(s, t, n)) {
    int tmp = inf;
    for (int i = t; i != s; i = pre[i])
     if (e[pos[i]].value < tmp) tmp = e[pos[i]].value;
    flow += tmp;
    cost += dis[t] * tmp;
    for (int i = t; i != s; i = pre[i]) {
     e[pos[i]].value -= tmp;
     e[pos[i] ^ 1].value += tmp;
    }
 }
 return cost;
}
struct node {
 int id, x, kind;
 node(){}
 node(int id,int x,int kind):id(id),x(x),kind(kind){}
} now, point[120];
set<int> idset;
set<int>::iterator it;
int n, l, r, np;
int cmp(const void*a, const void*b) {
 if (((node*) a)->x != ((node*) b)->x)
    return ((node*) a)->x - ((node*) b)->x;
 else
    return -((node*) a)->kind;
}
int mark[70], totalr;
void Scanner() {
 int i, j;
 totalr = 0;
 idset.clear();
 for (i = 0; i < np; i++) {
    if (i > 0 && point[i].x != point[i - 1].x) {
     totalr++;
     for (it = idset.begin(); it != idset.end(); it++) {
      add((*it) + 1, nv + totalr + 1, 1, nv - *it);
     }
     add(nv + totalr + 1, des, (point[i].x - point[i - 1].x), 0);
    }
    if (point[i].kind > 0)
     idset.insert(point[i].id);
    else
     idset.erase(idset.find(point[i].id));
 }
}
int main() {
 int i, j, n, m;
 int test;
 scanf("%d",&test);
 while (test--) {
    scanf("%d", &n);
    nv = n;
    memset(p, -1, sizeof (p));
    memset(mark, 0, sizeof (mark));
    cnt = 0;
    src = 0;
    des = 1;
    np = 0;
    for (i = 1; i <= n; i++) {
     scanf("%d%d", &l, &r);
     now.id = i;
     now.kind = 1;
     now.x = l;
     point[np++] = now;
     now.kind = -1;
     now.x = ++r;
     point[np++] = now;
     add(src, i + 1, 1, 0);
     mark[i] = cnt - 2;
    }
    qsort(point, np, sizeof (node), cmp);
    Scanner();
    int ans = min_cost_flow(src, des, nv + totalr + 1);
    printf("%d\n", flow);
    bool flag = 0;
    for (i = 1; i <= n; i++) {
     if (e[mark[i]].value == 0) {
      if (flag == 0) {
       flag = 1;
       printf("%d", i);
      } else {
       printf(" %d", i);
      }
     }
    }
    printf("\n");
  }
 return 0;
}
